home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / AIAT 1.0.1 / Headers / Accessor / RankedAccessor.h < prev    next >
Encoding:
Text File  |  1997-09-11  |  4.1 KB  |  124 lines  |  [TEXT/CWIE]

  1. // RankedAccessor.h
  2. //    Copyright:    © 1994 - 1996-1997 by Apple Computer, Inc., all rights reserved.
  3. /// abstract accessessor that defines interface for ranked searching,
  4. /// whether with a vector or an inverted index.
  5. #pragma once
  6.  
  7. #ifndef RankedAccessor_h
  8. #define RankedAccessor_h
  9.  
  10. #pragma import on
  11.  
  12. #include "IAAccessor.h"
  13. #include "TermIndex.h"
  14.  
  15. #pragma IA_BEGIN_EXPORTS
  16.  
  17. struct RankedQueryDoc {                // have to know which index each document belongs to
  18.                 RankedQueryDoc();
  19.                 RankedQueryDoc(IADoc* doc, TermIndex* index);
  20.     IADoc*        doc;
  21.     TermIndex*    index;
  22. };
  23.  
  24. class RankedHit : public IAHit {
  25. public:
  26.                     RankedHit(IAIndex* i, IADoc* d, float s, IATerm** ts, uint32 l);
  27.                     ~RankedHit();            // deletes matchingTerms
  28.  
  29.     RankedHit*        DeepCopy() const;        // copies matchingTerms
  30.     
  31.     void            SetScore(float value){score = value;}
  32.     float            GetScore() const {return score;}
  33.     IATerm**        GetMatchingTerms() const {return matchingTerms;}
  34.     uint32            GetMatchingTermsLen() const {return matchingTermsLen;}
  35.     
  36.  
  37. private:
  38.                     RankedHit(RankedHit&);
  39.     float            score;
  40.     IATerm**        matchingTerms;            // top scoring terms in intersection of doc w/ query
  41.     uint32            matchingTermsLen;
  42.     
  43.  
  44. };
  45.  
  46. class RankedProgress : public IAProgressReport {
  47. public:
  48.                     RankedProgress() : fTerm(NULL), IAProgressReport() {}
  49.     IA_INLINE        ~RankedProgress() IA_INLINE_DEF()                // no-op dtor def
  50.     IATerm*            GetTerm() const {return fTerm;}
  51.     void            SetTerm(IATerm* term) {fTerm = term;}
  52. private:
  53.     IATerm*            fTerm;    // when non-NULL, names term currently being processed.
  54. };
  55. typedef bool RankedProgressFn(const RankedProgress* progress, void* data);
  56.  
  57. class Similarity;
  58. class IAQuery;
  59. class WeightedTermQueue;
  60.  
  61. class RankedAccessor : public IAAccessor {
  62. public:
  63.         RankedAccessor(IAIndex** indices, uint32 indexCount, uint32 type);
  64.         ~RankedAccessor();
  65.  
  66.     virtual uint32    RankedSearch(byte*                 textQuery,     uint32     textQueryLen,
  67.                                  RankedQueryDoc*        docQuery,     uint32     nDocs,
  68.                                  RankedHit**            results,    uint32    resultLen,
  69.                                  uint32                matchingTermsLen,
  70.                                 RankedProgressFn*    progressFn,
  71.                                  clock_t                progressFreq,
  72.                                  void*                appData) = 0;
  73.  
  74.     virtual uint32    RankedSearch(IADocText*         textQuery,
  75.                                  RankedQueryDoc*        docQuery,     uint32     nDocs,
  76.                                  RankedHit**            results,    uint32    resultLen,
  77.                                  uint32                matchingTermsLen,
  78.                                 RankedProgressFn*    progressFn,
  79.                                  clock_t                progressFreq,
  80.                                  void*                appData) = 0;
  81.  
  82.     virtual uint32    GetDocTopic(RankedQueryDoc*        doc,
  83.                                  IATerm**            results,    uint32    resultLen,
  84.                                 RankedProgressFn*    progressFn,
  85.                                  clock_t                progressFreq,
  86.                                  void*                appData);
  87.  
  88.     virtual uint32    GetTermsRelated(byte*             term,     uint32     termLen,
  89.                                  IATerm**            results,    uint32    resultLen,
  90.                                 RankedProgressFn*    progressFn,
  91.                                  clock_t                progressFreq,
  92.                                  void*                appData);
  93.  
  94.     // called to filter hits -- default always returns true
  95.     virtual bool        IsHit(IAIndex* index, const IADoc* doc);
  96.     // determines merging of hits -- defaults are d1->LessThan(d2) and d1->Equal(d2)
  97.     virtual bool        HitLessThan(IAIndex* i1, const IADoc* d1, IAIndex* i2, const IADoc* d2);
  98.     virtual bool        HitEqual(IAIndex* i1, const IADoc* d1, IAIndex* i2, const IADoc* d2);
  99.     // merges hits that are HitEqual() into one hit -- default copies higher scoring
  100.     virtual RankedHit*    MergeHits(const RankedHit* hit1, const RankedHit* hit2);
  101. protected:
  102.     Similarity*            GetSimilarity() const {return sim;}
  103.     // default constructor etc. so that this can be a virtual base class
  104.                         RankedAccessor();
  105.     void                Constructing(IAIndex** indices, uint32 indexCount, uint32 type);
  106.     bool                IsRankedCoordinated() const {return RankedCoordination;}
  107.     void                SetRankedCoordination(bool coord = true) {RankedCoordination = coord;}
  108.     void                SetRankedCoordinationDegree(float deg);
  109.     float                GetRankedCoordinationDegree() const;
  110. private:
  111.     uint32                GetDocTopicInternal(RankedQueryDoc*        doc,
  112.                                  WeightedTermQueue* results, uint32    resultLen,
  113.                                 RankedProgressFn*    progressFn,
  114.                                  clock_t                progressFreq,
  115.                                  void*                appData);
  116.  
  117.     Similarity*            sim;
  118.     bool        RankedCoordination;       // Determines whether short queries use coordination ranking.
  119. };
  120.  
  121. #pragma IA_END_EXPORTS
  122.  
  123. #pragma import reset
  124. #endif